//
//  AddClockViewController.m
//  SmartWatch
//
//  Created by zwj on 2022/11/22.
//

#import "AddClockViewController.h"
#import "BRDatePickerView.h"
@interface AddClockViewController ()<UIPickerViewDelegate,UIPickerViewDataSource>
@property(nonatomic,strong) NSMutableArray *hourArray;
@property(nonatomic,strong) NSMutableArray *minuteArray;
@property(nonatomic,strong) NSMutableArray *selectArray;
@end

@implementation AddClockViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"新建闹钟";
    self.view.backgroundColor = BACKGROUNDCOLOR;
    self.selectArray = @[].mutableCopy;
    self.hourArray = @[].mutableCopy;
    self.minuteArray = @[].mutableCopy;
    
    
    for (int i = 0; i < 24; i++) {
        [self.hourArray addObject:@(i)];
    }
    for (int i = 0; i < 60; i++) {
        [self.minuteArray addObject:@(i)];
    }
    
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [rightBtn setTitle:@"保存" forState:UIControlStateNormal];
    [rightBtn setTitleColor:THEME_COLOR forState:UIControlStateNormal];
    rightBtn.titleLabel.font = UIFontMake(15);
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    
    
    MyLinearLayout *root = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
    root.myHorzMargin = 15;
    root.myTop = NavigationContentTop + 15;
    root.padding = UIEdgeInsetsMake(15, 15, 30, 15);
    root.layer.cornerRadius = 15;
    root.myHeight = kAutoHeight;
    root.subviewVSpace = 15;
    root.backgroundColor = COLOR_4;
    [self.view addSubview:root];
    
    UIPickerView *selectView = [UIPickerView new];
    selectView.delegate = self;
    selectView.dataSource = self;
    selectView.myHorzMargin = 0;
    selectView.myHeight = 180;
    [root addSubview:selectView];
    
    [selectView selectRow:10 inComponent:0 animated:YES];
    [selectView selectRow:20 inComponent:1 animated:YES];
    
    [root addSubview:[self setAddLineTop:0]];
    
    UILabel *title = [UILabel createLabelText:@"重复" font:UIFontMake(15) textColor:COLOR1515];
    title.mySize = kAutoSize;
    [root addSubview:title];
    
    MyLinearLayout *riqiLay = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
    riqiLay.myHorzMargin = 0;
    riqiLay.gravity = MyGravity_Vert_Center | MyGravity_Horz_Between;
    riqiLay.myHeight = 40;
    [root addSubview:riqiLay];
    
    NSArray *array = @[@"日",@"一",@"二",@"三",@"四",@"五",@"六"];
    for (int i = 0; i < array.count; i++) {
        UIButton *item = [UIButton createButtonText:array[i] font:UIFontMake(12) textColor:COLOR1515];
        [item setTitleColor:COLOR_4 forState:UIControlStateSelected];
        item.mySize = CGSizeMake(32, 32);
        ViewCorner(item, 16);
        item.tag = 10 + i;
        [item addTarget:self action:@selector(itemClick:) forControlEvents:UIControlEventTouchUpInside];
        [item setBackgroundImage:[UIImage imageWithColor:HexColor(@"#F5F5F5")] forState:UIControlStateNormal];
        [item setBackgroundImage:[UIImage imageWithColor:THEME_COLOR] forState:UIControlStateSelected];
        [riqiLay addSubview:item];
    }
    
    
}

- (void)itemClick:(UIButton *)sender {
    NSInteger tag = sender.tag - 10;
    
    sender.selected = !sender.selected;
    
    if(sender.selected) {
        [self.selectArray addObject:@(tag)];
    }else{
        [self.selectArray removeObject:@(tag)];
    }
    [QMUIConsole log:FormatString(@"self.selectArray = %@",self.selectArray)];
}



- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 2;
}


- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if(component == 0){
        return  self.hourArray.count;
    }else{
        return self.minuteArray.count;
    }
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    
    if(component == 0){
        return  [self.hourArray[row] stringValue];
    }else{
        return [self.minuteArray[row] stringValue];
    }
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    
}

-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
    return 40;
}

@end
